package com.yangguang.huahui.app;

import android.app.Activity;
import android.app.ActivityManager;
import android.app.Application;
import android.content.Context;
import android.content.pm.PackageManager;
import android.support.multidex.MultiDex;
import android.util.Log;

import com.hyphenate.chat.EMClient;
import com.hyphenate.chat.EMOptions;
import com.hyphenate.easeui.controller.EaseUI;
import com.netease.scan.QrScan;
import com.netease.scan.QrScanConfiguration;
import com.yangguang.huahui.R;
import com.yangguang.huahui.easemob.AppHelper;
import com.yangguang.huahui.utils.LogUtil;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import static com.hyphenate.chat.EMGCMListenerService.TAG;

/**
 * Created by Administrator on 2017/2/28.
 */

public class App extends Application {
    private static List<Activity> activitys = new ArrayList<Activity>();
    public static Context context;
    private static App instance;

    @Override
    public void onCreate() {
        super.onCreate();
        initQRCode();
        MultiDex.install(this);
        context = this;
        instance = this;
        AppHelper.getInstance().init(context);
    }

    public static App getInstance() {
        return instance;
    }

    public void addActivity(Activity activity) {
        activitys.add(activity);
    }

    public List<Activity> getActivitys() {
        return activitys;
    }

    public boolean hasForegroundActivies() {
        return activitys.size() != 0;
    }

    public void exit(Context context) {
        if (activitys != null && activitys.size() > 0) {
            for (Activity activity : activitys) {
                activity.finish();
            }
        }
        System.exit(0);
    }

    private void initQRCode(){
        // 自定义配置
        QrScanConfiguration configuration = new QrScanConfiguration.Builder(this)
                .setTitleHeight(53)
                .setTitleText("扫一扫")
                .setTitleTextSize(18)
                .setTitleTextColor(R.color.white)
                .setTipText("将二维码放入框内扫描~")
                .setTipTextSize(14)
                .setTipMarginTop(40)
                .setTipTextColor(R.color.white)
                .setSlideIcon(R.drawable.capture_add_scanning)
                .setAngleColor(R.color.white)
                .setMaskColor(R.color.black_80)
                .setScanFrameRectRate((float) 0.8)
                .build();
        QrScan.getInstance().init(configuration);
    }
}
